﻿<?php 
include ('layout/header.php'); 
include ('common/paging.php'); 
?>

<?php
    $DALAcc = new DALUserAccount();
    $user = $DALAcc->getUser();
    $balance = $user['balance'];
    $status = $user['active'];
?>
<?php
    $page = Utils::getValGet('pn');
    $page = (int) $page;
    $page = ($page == 0) ? 1 : $page;

    $paging = new paging($page, "main.php");
    $itemPerPage = $paging->rowLimit;
    //load settledContract
    $dal = new DALSettledContract();
    $data = $dal->getListSettled('modify_timestamp', 'desc', $page, $itemPerPage);

    $totalRow = $dal->count();
    $paging->totalCount = $totalRow;
    $paging->doPaging();      
?>

<script type="text/javascript">
	$( document ).ready(function() { 
		var matches = <?php echo json_encode($data); ?> ;
		registerHelper();
		initPage(matches);
	});
</script>
<div class='info' style="overflow: hidden">
    <h3><span class='balanceWrapper' style='float:left;'>Account : <span id="balance"><?= $balance ?></span></span></h3>
    <button style="float:right;" id="btnManage" type="button" class="btn btn-<?= ($status == '1') ? 'danger' : 'primary' ?>"><?= ($status == '1') ? 'Stop' : 'Start' ?></button>
</div>
	<?php Utils::print_paging($paging); ?>
    <div class="checkbox">
		<label>
		  <input type="checkbox" name="cbBetSlip" id="cbBetSlip"/> Hiện kèo
		</label>
		<div class="working"></div>
	</div>
       <div class="table-responsive">
            <table class="table table-striped table-bordered table-condensed">
                <thead>
                    <tr>
                        <th>Giải</th>
                        <th>Chủ</th>
                        <th>Khách</th>
                        <th>Phút</th>
                        <th>Số Trái</th>
                        <th>Under</th>
                        <th>Số tiền</th>
                        <th>Tỉ lệ</th>
                        <th>Status</th>
                        <td class="bet_slip">[Bắt]<br/>Trái</td>
                        <td class="bet_slip">[Bắt]<br/>Phút</td>
                        <td class="bet_slip">[Bắt]<br/>Ăn</td>
                        <th class="bet_slip">Updated on</th>
                        <th class="bet_slip">Kèo</th>
                    </tr>
                </thead>
                <tbody id="matchTableRow">      
				</tbody>
            </table>
            <?php Utils::print_paging($paging); ?>
        </div>
<script type="text/x-handlebars-template" id="matchTemplate">
	{{#each matches}}
            <tr>
                <input type="hidden" name="id_{{ id }}"/>
                <input type="hidden" name="contractid_{{ contract_id }}"/>
                <td class="match-table column league">{{ country_name }}<br/>{{ league_name }}</td>
                <td class="match-table column home-name">{{ home_name }}</td>
                <td class="match-table column away-name">{{ away_name }}</td>
                <td class="match-table column current-time">{{ current_time }}</td>
                <td class="match-table column">{{ current_goal }}</td>
                <td class="match-table column">{{ under_goal }}</td>
                <td class="match-table column">{{ trimNumber bet_amount }}</td>
                <td class="match-table column">{{ trimNumber rate }}</td>
                <td class="status {{ rowStatus this }} match-table column">{{ won }}</td>
                <td class="bet_slip match-table column" style="display: table-cell;">{{ settled_total_goals }}</td>
                <td class="bet_slip match-table column" style="display: table-cell;">{{ settled_play_time }}</td>
                <td class="bet_slip match-table column" style="display: table-cell;">{{ trimNumber won_amount }}</td>
                <td class="bet_slip match-table column" style="display: table-cell;">{{ modify_timestamp }}</td>
                <td class="bet_slip match-table column bet_slip_detail" style="display: table-cell;">{{ bet_slip }}</td>
            </tr>
	{{/each}}
</script>


<?php include ('layout/footer.php'); ?>